package com.ksd.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ksd.common.annotation.Log;
import com.ksd.common.core.controller.BaseController;
import com.ksd.common.core.domain.AjaxResult;
import com.ksd.common.core.page.TableDataInfo;
import com.ksd.common.enums.BusinessType;
import com.ksd.common.utils.StringUtils;
import com.ksd.common.utils.poi.ExcelUtil;
import com.ksd.system.service.ISysTvDataService;
import com.ksd.system.service.ISysTvTypeService;
import com.ksd.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ksd.system.domain.SysBatch;
import com.ksd.system.service.ISysBatchService;

/**
 * 批次管理Controller
 * 
 * @author y.wu
 * @date 2025-01-23
 */
@RestController
@RequestMapping("/system/batch")
public class SysBatchController extends BaseController
{
    @Autowired
    private ISysBatchService sysBatchService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysTvTypeService sysTvTypeService;
    @Autowired
    private ISysTvDataService sysTvDataService;

    /**
     * 查询批次管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:batch:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBatch sysBatch)
    {
        startPage();
        List<SysBatch> list = sysBatchService.selectSysBatchList(sysBatch);
        return getDataTable(list);
    }

    /**
     * 导出批次管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:batch:export')")
    @Log(title = "批次管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBatch sysBatch)
    {
        List<SysBatch> list = sysBatchService.selectSysBatchList(sysBatch);
        ExcelUtil<SysBatch> util = new ExcelUtil<SysBatch>(SysBatch.class);
        util.exportExcel(response, list, "批次管理数据");
    }

    /**
     * 获取批次管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:batch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysBatchService.selectSysBatchById(id));
    }

    /**
     * 新增批次管理
     */
    @PreAuthorize("@ss.hasPermi('system:batch:add')")
    @Log(title = "批次管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBatch sysBatch)
    {
        return toAjax(sysBatchService.insertSysBatch(sysBatch));
    }

    /**
     * 修改批次管理
     */
    @PreAuthorize("@ss.hasPermi('system:batch:edit')")
    @Log(title = "批次管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBatch sysBatch)
    {
        return toAjax(sysBatchService.updateSysBatch(sysBatch));
    }

    /**
     * 删除批次管理
     */
    @PreAuthorize("@ss.hasPermi('system:batch:remove')")
    @Log(title = "批次管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysBatchService.deleteSysBatchByIds(ids));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        sysBatchService.cleanBatch();
        return success();
    }
}
